<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/16
 * Time: 13:33
 */

namespace traits\controller;
use think\Config;
trait  Plugins
{

    private         $observers          =       [];
    private         $trigger_action     =       'getUpdate';

    public function attach($name,$observer)
    {
        $this->observers[$name] =$observer;
    }



    public function detach($name)
    {
        if(array_key_exists($name,$this->observers))
        unset($this->observers[$name]);
    }



    public function notify()
    {
       $controllerPrefix        =   Config::get('controller_suffix') || false;
       $data                    =   [];
       foreach($this->observers as $key=>$observer){
          $data[]   = action($observer.chr(47).$this->trigger_action,[],'controller',$controllerPrefix);
       }
      return $data;
    }

    public function trigger(){
       return  $this->notify();
    }

}